package com.sds.shop.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sds.fw.mvc.Action;
import com.sds.fw.mvc.HttpUtil;
import com.sds.shop.dao.MemDAO;
import com.sds.shop.vo.MemVO;
import com.sds.shop.vo.SessionVO;

public class UpdateUsrAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		MemDAO mdao = MemDAO.getInstance();
		MemVO mvo = new MemVO();
		request.setCharacterEncoding("euc-kr");
		String orgMemId = request.getParameter("memId");
		
		System.out.println(orgMemId);
		String memId = request.getParameter("memId");
		String memNm = request.getParameter("memNm");
		String pwd = request.getParameter("pwd");
		String pwd_hint = request.getParameter("pwd_hint");
		String pwd_hint_ans = request.getParameter("pwd_hint_ans");
		String ssn = request.getParameter("ssn");
		String birth_dt = request.getParameter("birth_dt");
		String male_flg = request.getParameter("male_flg");
		String tel_no = request.getParameter("tel_no");
		String cell_no = request.getParameter("cell_no");
		String addr = request.getParameter("addr");
		String email = request.getParameter("email");
		String email_rcv_flg = request.getParameter("email_rcv_flg");
		
		System.out.println(email);
		
		mvo.setMemId(memId);
		mvo.setMemNm(memNm);
		mvo.setPwd(pwd);
		mvo.setPwdHint(pwd_hint);
		mvo.setPwdHintAns(pwd_hint_ans);
		mvo.setSsn(ssn);
		mvo.setBirthDt(birth_dt);
		mvo.setMaleFlg(male_flg);
		mvo.setTelNo(tel_no);
		mvo.setCellNo(cell_no);
		mvo.setAddr(addr);
		mvo.setEmail(email);
		mvo.setEmailRcvFlg(email_rcv_flg);
		
		
		mdao.updateMember(mvo,orgMemId);
		
		SessionVO svo = new SessionVO();
		svo.setMemId(mvo.getMemId()); 
		svo.setMemNm(mvo.getMemNm());
		svo.setMemCd("USR"); 
		svo.setEmail(mvo.getEmail()); 
		
		HttpSession session = request.getSession();
		session.removeAttribute("user");
		session.setAttribute("user", svo);
		


		HttpUtil.forward(request, response, "/index.jsp");
	}

}
